<template>
  <PanelLayout>
    <div class="bottom-cell">
      <div class="title">风场功率MW</div>
      <div class="list-wrap">
        <div class="chart-box">
          <BarChart :options="options" />
        </div>
        <div class="total">
          <div class="title">风场总有<br />功功率MW</div>
          <div class="value">{{ total }}</div>
        </div>
      </div>
    </div>
  </PanelLayout>
</template>

<script setup name="BottomCenter">
import { computed } from 'vue'
import PanelLayout from '@/views/index/PanelLayout.vue'
import BarChart from '@/components/Charts/BarChart.vue'
import { getFcGLData } from '@/api/base.js'

import useAppStore from '@/store/modules/app'
const appStore = useAppStore()

const options = ref({
  xAxis: [],
  series: []
})

const total = computed(() => {
  return (options.value.series.reduce((prev, curr) => prev + curr, 0) / 1000000).toFixed(2)
})

const init = () => {
  const time = appStore.timePoint
  // 模拟接口获取数据
  getFcGLData({ time: time }).then(res => {
    if (res.code == '0000') {
      options.value = res.data
    }
  })
  // options.value = {
  //   xAxis: Array.from({ length: 12 }, (e, i) => `风电场${i + 1}`),
  //   series: Array.from({ length: 12 }, () => Math.floor(Math.random() * 200))
  // }
  // console.log(options.value)
}

init()

watch(
  () => appStore.timePoint,
  () => {
    init()
  }
)
</script>

<style lang="scss" scoped>
.bottom-cell {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  .title {
    font-size: 18px;
    height: 16px;
  }
  .list-wrap {
    width: 100%;
    flex: 1;
    display: flex;
    .chart-box {
      flex: 1;
      height: 100%;
    }
    .total {
      width: 100px;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      gap: 20px;
      .title {
        text-align: center;
        height: initial;
        line-height: 1.5;
      }
      .value {
        font-size: 30px;
        font-weight: bold;
      }
    }
  }
}
</style>
